<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function Xhr() {
            var xhr = null;
            if (window.XMLHttpRequest)
            {
                //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                xhr=new XMLHttpRequest();
            }
            else
            {
                // IE6, IE5 浏览器执行代码
                xhr=new ActiveXObject("Microsoft.XMLHTTP");
            }
            return xhr;
        }
        function getText() {
            //1. 创建XMLHttpRequest对象
            var xhr = Xhr();
            //2. 与服务器建立连接并发送请求
            xhr.open("get","getText",true);
            xhr.send(null);
            //3. 从服务器端获取数据并在前台接收数据
            xhr.onreadystatechange=function()
            {
                if (xhr.readyState==4 && xhr.status==200)
                {
                    var txt = xhr.responseText;
                    var objects = eval("("+txt+")");
                    alert(objects.id);
                }
            }
        }
    </script>
</head>
<body>
<a href="###" onclick="getText()">ajax_demo</a>

</body>
</html>